package cn.fintecher.gis.web;

import cn.fintecher.gis.annotation.CurrentOperator;
import cn.fintecher.gis.enums.RiskGrand;
import cn.fintecher.gis.enums.SusceptibleGrand;
import cn.fintecher.gis.model.request.LandDisasterRequest;
import cn.fintecher.gis.model.response.LandDisasterResponse;
import cn.fintecher.gis.model.session.SessionModel;
import cn.fintecher.gis.service.LandDisasterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

@RestController
@RequestMapping("/api/landDisasterController")
@Api(value = "隐患点信息", description = "隐患点信息")
public class LandDisasterController {

    private final Logger logger = LoggerFactory.getLogger(LandDisasterController.class);

    @Autowired
    private LandDisasterService landDisasterService;

    @GetMapping("/queryLandDisasterAll")
    @ApiOperation(value = "查询所有的隐患点信息", notes = "查询所有的隐患点信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", dataType = "int", paramType = "query",
                    value = "页数 (0..N)"),
            @ApiImplicitParam(name = "size", dataType = "int", paramType = "query",
                    value = "每页大小."),
            @ApiImplicitParam(name = "sort", allowMultiple = true, dataType = "string", paramType = "query",
                    value = "依据什么排序: 属性名(,asc|desc). ")
    })
    public ResponseEntity<Page<LandDisasterResponse>> queryLandDisasterAll(Pageable pageable,
                                                                           @RequestParam(value = "name", required = false) String name,
                                                                           @RequestParam(value = "grade", required = false) RiskGrand grade,
                                                                           @RequestParam(value = "susceptible", required = false) SusceptibleGrand susceptible) {
        Page<LandDisasterResponse> page = landDisasterService.queryLandDisasterAll(pageable, name, grade, susceptible);
        return ResponseEntity.ok().body(page);
    }

    @GetMapping("/getLandDisasters")
    @ApiOperation(value = "查询所有的隐患点信息（不分页）", notes = "查询所有的隐患点信息（不分页）")
    public ResponseEntity<List<LandDisasterResponse>> getLandDisasters(@RequestParam(value = "grade", required = false) RiskGrand grade) {
        List<LandDisasterResponse> list = landDisasterService.getLandDisaster(grade);
        return ResponseEntity.ok().body(list);
    }

    @PostMapping("/createLandDisaster")
    @ApiOperation(value = "隐患点信息的创建", notes = "隐患点信息的创建")
    public ResponseEntity<Void> saveLandDisaster(@RequestBody LandDisasterRequest request,
                                                 @ApiIgnore @CurrentOperator SessionModel sessionModel) {
        landDisasterService.createLandDisaster(request, sessionModel);
        return ResponseEntity.ok().build();
    }

    @PostMapping("/editLandDisaster")
    @ApiOperation(value = "隐患点信息的修改", notes = "隐患点信息的修改")
    public ResponseEntity<Void> editLandDisaster(@RequestBody LandDisasterRequest request,
                                                 @ApiIgnore @CurrentOperator SessionModel sessionModel) {
        landDisasterService.editLandDisaster(request);
        return ResponseEntity.ok().build();
    }
}
